﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BAL.Controller;
using EntityObjects;

namespace PresentationLayer.View.StoreClerk
{
    public partial class ViewDisbursementList : System.Web.UI.Page
    {
        ViewDisbursementListForStoreControl control;
      
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Department> deptList = new List<Department>();
            control = new ViewDisbursementListForStoreControl();
            if (!IsPostBack)
            {
                deptList = control.getDisbursedDepartment();
                ddDepartment.DataSource = deptList;
                ddDepartment.DataTextField = "deptName";
                ddDepartment.DataValueField = "deptId";
                ddDepartment.DataBind();

                gvDisbursementList.DataSource = null;
                gvDisbursementList.DataBind();

                Panel1.Visible = false;
            }
            else
            {
                List<DisbursementCatalogue> result = control.getDisbursementByDeptId(ddDepartment.SelectedItem.Value);
                gvDisbursementList.DataSource = result;
                gvDisbursementList.DataBind();
                Panel1.Visible = true;
                Department d = control.getDeptInfo(ddDepartment.SelectedItem.Value);
                lbDeptName.Text = d.DeptName;
                CollectionPoint c = control.getColPt(d.CollectionId);
                lbCP.Text = c.Place;
                Employee ep = control.getEmp(d.RepresentativeId);
                lbRname.Text = ep.EmpName;
            }
        }

        protected void ddDepartment_SelectedIndexChanged(object sender, EventArgs e)
        {
           
           
        }

        protected void btnPrint_Click(object sender, EventArgs e)
        {
            CreatePDF printfile = new CreatePDF();
            List<DisbursementCatalogue> result = control.getDisbursementByDeptId(ddDepartment.SelectedItem.Value);

            Department d = control.getDeptInfo(ddDepartment.SelectedItem.Value);
            CollectionPoint c = control.getColPt(d.CollectionId);
            Employee ep = control.getEmp(d.RepresentativeId);

            string[] head = { d.DeptName, c.Place, ep.EmpName };
            printfile.createDisbursementListFile(result, head);
            Response.Redirect("PDFs/disursementList.pdf");
        }
    }
}